Improperly Nested Constructs

Contents|Index|Previous|Next
Improperly nested constructs

Recall that when a macro is called with arguments, the arguments are substituted into the macro body and the result is checked, together with the rest of the input file, for more macro calls. It is possible to piece together a macro call coming partially from the macro body and partially from the actual arguments. Use the following input as an example.

    #define double(x) (2*(x))
    #define call_with_1(x) x(1)

This input would expand ‘call_with_1 (double)’ into a ‘(2*(1))’ argument.

Macro definitions do not have to have balanced parentheses. By writing an unbalanced open parenthesis in a macro body, it is possible to create a macro call that begins inside the macro body but ends outside of it. Use the following input as an example.

    #define strange(file) fprintf (file, "%s %d",
    . . .
    strange(stderr) p, 35)

The previous bizarre example expands to the following output.

    fprintf (stderr, "%s %d", p, 35)

Top|Contents|Index|Previous|Next